//PirateShip Wars
//Originally made in gmod 9 by EmpV
//Remade for gmod 10 by Metroid48 and Termy58

Msg("\nLoading client-side PirateShip Wars.\n")

include("shared.lua")

////
//Language additions
////

//language.Add( "#func_physbox", "Cannonball LOLZ" )
language.Add( "func_physbox", "Cannonball LOLZ" )
language.Add( "env_explosion", "Ship 'SPLOSION" )
language.Add( "func_breakable", "Ship FLATTEN u!" )
language.Add( "worldspawn", "Ship FLATTEN u!" )

////
//Menus
////

helpVis = false
local helpText = {"\nArrr! Destroy the enemy pirate ship\n",
"or be sent to Davy Jones locker!\n",
"Man the cannons, set sail an\' steer\n",
"the ship.\n",
"\n\nPress F2 if your current crew\n",
"displeases you, an\' press F1\n",
"if you forget these here\n",
"instructions."}

helpFrame = vgui.Create("Frame")
helpFrame:SetSize(200,200)
helpFrame:SetPos(ScrW()*0.5-100, ScrH()*0.5-100)
helpFrame:PostMessage( "SetTitle", "text", "Pirate Ship Wars Help!" )

helpFrameText = vgui.Create("Label", helpFrame)
helpFrameText:SetSize(180,190)
helpFrameText:SetPos(5, 8)
helpFrameText:SetText(table.concat(helpText))

function helpMenu( msg ) //F1
	if msg:ReadShort()==7 then
		helpVis = !helpVis
		helpFrame:SetVisible(helpVis)
		if helpVis then
			helpFrame:MakePopup()
		end
	end
end
usermessage.Hook("HelpMenu", helpMenu)

teamVis = false

teamFrame = vgui.Create("Frame")
teamFrame:SetSize(400,200)
teamFrame:SetPos(ScrW()*0.5-200,ScrH()*0.5-100)
teamFrame:PostMessage( "SetTitle", "text", "Team Select" )


function teamMenu( msg ) //F2

	if msg:ReadShort()!=8 then return end
	teamVis = !teamVis
	if !teamVis then
		teamFrame:SetVisible(true)
		teamFrame:MakePopup()
		
		Text1 = vgui.Create("Label", teamFrame) //Red pirates listing
		Text1:SetSize(120,180)
		Text1:SetPos(5, 10)
//		Text1:SetPos(ScrW()*0.5-95, ScrH()*0.5-90)
		
		local plys = player.GetAll()
		local tempList = {}
		for k,v in pairs(plys) do
			if v:Team()==TEAM_RED then
				table.insert(tempList, v:GetName().."\n")
			end
		end
		Text1:SetText(table.concat(tempList))
		
		Text2 = vgui.Create("Label", teamFrame) //Blue pirates listing
		Text2:SetSize(120,180)
		Text2:SetPos(205, 10)
		
		tempList = {}
		for k,v in pairs(plys) do
			if v:Team()==TEAM_BLUE then
				table.insert(tempList, v:GetName().."\n")
			end
		end
		Text2:SetText(table.concat(tempList))
		
		Button1 = vgui.Create("Button", teamFrame) //Red pirate switch button
		Button1:SetPos(50,180)
		Button1:SetText( "Switch" )
		function Button1:DoClick()
			LocalPlayer():ConCommand("psw_switch "..tostring(TEAM_RED))
		end
		
		Button2 = vgui.Create("Button", teamFrame) //Blue pirate switch button
		Button2:SetPos(250,180)
		Button2:SetText( "Switch" )
		function Button2:DoClick()
			LocalPlayer():ConCommand("psw_switch "..tostring(TEAM_BLUE))
		end
	else
		teamFrame:SetVisible(false)
	end
end
usermessage.Hook("TeamMenu", teamMenu)